<div class="row">
	<div class="col-md-12">
		<ol class="breadcrumb">
			<li>
				<a href="#" onclick="toHome()">
					主页
				</a>
			</li>
			<li class="active">
				太电影打卡影片列表
			</li>
		</ol>
	</div>
</div>
<form role="form" class="form-horizontal">
	<div class="row page-cont">
		<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 cont-top">
			<div class="panel panel-white">
				<div class="panel-heading">
					<h4 class="panel-title">
						<span class="title-text">检索影片</span>
					</h4>
					<div class="panel-tools">
						<div class="dropdown">
							<a data-toggle="dropdown" class="btn btn-xs dropdown-toggle btn-transparent-grey">
								<i class="fa fa-cog"></i>
							</a>
							<ul class="dropdown-menu dropdown-light pull-right" role="menu">
								<li>
									<a class="panel-collapse collapses" href="#"><i class="fa fa-angle-up"></i> <span>折叠</span> </a>
								</li>
								<li>
									<a class="panel-expand" href="#">
										<i class="fa fa-expand"></i> <span>全屏</span>
									</a>
								</li>
							</ul>
						</div>
						<a class="btn btn-xs btn-link panel-close" href="#">
							<i class="fa fa-times"></i>
						</a>
					</div>
				</div>
				<div class="panel-body">
					<div class="form-group panel-cont">
					    <label class="col-sm-2 control-label">月份</label>
					    <div class="col-sm-4">
					      <input type="text" class="form-control" id="movie-mouth" />
					    </div>
				  	</div>
				  	<div class="form-group">
				  		<div class="col-sm-5 col-sm-offset-5">
				  			<button type="button" class="btn btn-primary query-btn">查询</button>
				  			<button type="reset" class="btn">重置</button>
				  		</div>
				  	</div>
				</div>
			</div>
		</div>
		<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 cont-bottom">
			<div class="panel panel-white">
				<div class="panel-heading">
					<h4 class="panel-title">
						<span class="title-text">列表</span>
					</h4>
					<div class="panel-tools">
						<div class="dropdown">
							<a data-toggle="dropdown" class="btn btn-xs dropdown-toggle btn-transparent-grey">
								<i class="fa fa-cog"></i>
							</a>
							<ul class="dropdown-menu dropdown-light pull-right" role="menu">
								<li>
									<a class="panel-collapse collapses" href="#"><i class="fa fa-angle-up"></i> <span>折叠</span> </a>
								</li>
								<li>
									<a class="panel-expand" href="#">
										<i class="fa fa-expand"></i> <span>全屏</span>
									</a>
								</li>
							</ul>
						</div>
						<a class="btn btn-xs btn-link panel-close" href="#">
							<i class="fa fa-times"></i>
						</a>
					</div>
				</div>
				<div class="row table-btn">
					<div class="col-sm-12">
						<button type="button" class="btn btn-success add-btn">新增&nbsp;<i class="fa fa-plus"></i></button>
					</div>
				</div>				
				<div class="panel-body table-body">
					<table class="table table-bordered table-hover">
						<thead>
							<tr>
								<th class="hidden-xs">id</th>
								<th class="hidden-xs">月份</th>
								<th class="hidden-xs">图片URL</th>
								<th class="hidden-xs">操作</th>
							</tr>
						</thead>
						<tbody>
							<tr>
								<td></td>
								<td></td>
								<td>
									
								</td>
							</tr>
						</tbody>
					</table>
					<div class="M-box3 page-style"></div>
				</div>
			</div>
		</div>
	</div>
</form>
<script>
	/*********************************变量***********************************/
	var pageNo = 1;    // 第几页
	var pageSize = 5; // 每页几条
	var totalPage;     // 总页数
	var totalData;     // 总条数
	var username = GetQueryString("username");    // 用户姓名
	var token = MXCookie.get("token",token);      // 登陆token   
	/*********************************事件***********************************/

	// 新增
	toOperat($(".add-btn"),"view/taiMovie/add-list.html");

	// 查询
	$(".query-btn").click(function(){
		getList();
	});

	// 不删除
	$("body").on("click",".ask-no",function(){
		$(".ask-alert").fadeOut();	        	
    });		

    // 关闭弹框
	$("body").on("click",".close-icon",function(){
		$(".ask-alert").fadeOut();	        	
    });				


	/*********************************函数***********************************/
	// 获取列表
	function getList() {
		$("tbody").html("");
		$.ajax({
			url: localStorage.grobalUrl + "/man/urlList",
			type: "post",
			async:false,
			data:{
				username: username,
				token: token,  
				pageNo: pageNo,   
				pageSize: pageSize,
				type: $("#movie-mouth").val()
			},
			success: function(data){
				console.log(data);
				var str =  '<tr align="center">'+
								'<td class="tai-id"></td>'+
								'<td class="tai-mouth"></td>'+
								'<td class="tai-img">'+
									'<img src="" />'+
								'</td>'+
								'<td>'+
									'<button type="button" class="btn btn-dark-yellow check-btn">查看&nbsp;<i class="fa fa-eye"></i></button>'+
									'<button type="button" class="btn btn-red delete-btn">删除&nbsp;<i class="fa fa-trash-o"></i></button>'+
								'</td>'+
							'</tr>';
				if(data.errCode == "00005"){
					tips("请重新登陆");
					setTimeout(function(){
						window.location.href = "login_login.html";
					},500);
				}else if (data.urls){
				  	var dataVal = data.urls.list;
			        totalPage = data.urls.totalPage;
			        totalData = data.urls.totalRow;
			        for(var i = 0; i < dataVal.length; i ++){
			            var listVal = dataVal[i];
			            $("tbody").append(str);
			            $(".tai-id").eq(i).text(listVal.id);
			            $(".tai-mouth").eq(i).text(listVal.type + "月");
			            $(".tai-img img").eq(i).attr("src",listVal.url);
			        }


			        // 删除
			        $(".delete-btn").click(function(){
						var index = $(".delete-btn").index(this);
			            var listId = $(".tai-id").eq(index).text();
			            askAlert("是否要删除");
			            $(".ask-alert").attr("data-id",listId).attr("data-index",index);			        	
			        });
			  
			        // 查看
					$(".check-btn").click(function(){
				        var index = $(".check-btn").index(this);
				        var listId = $(".tai-id").eq(index).text();
				        $(".pageAdd").attr("data-id",listId);
				        pageUrl = "view/taiMovie/view-list.html";
				        url = pageUrl;
				        getPage(url); 
				    });				        
				}else{
				  $("tbody").append("<tr><td align='center' colspan='4'>暂无数据</td></tr>");
				}
					
			},
			error: function(error){
				console.log(error);
			}
		});	
	}
	getList();

	// // 分页
	pageSetGet();


	// 确定删除
	function dialogyYesBtn () {
		var listId = $(".ask-alert").attr("data-id");
		var index = $(".ask-alert").attr("data-index");
    	deleteList(listId,index);	
	}	


	// 删除
	function deleteList(listId,index){
		$.ajax({
			url: localStorage.grobalUrl + "/man/deleteImg",
			type: "post",
			data:{
				username: username,
				token: token,
				id: listId
			},
			success: function(data){
				console.log(data);
				if(data.errCode == "00000"){
					$(".delete-btn").eq(index).parent().parent().remove();
					$(".ask-alert").fadeOut();
					tips("已删除");
				}else if(data.errCode == "00005"){
					tips("请重新登陆");
					setTimeout(function(){
						window.location.href = "login_login.html";
					},500);					
				}else{
					tips("删除失败");
				}								
			},
			error: function(err){
				console.log(err);
			}
		});
	}
	
</script>
